package bb.lanxing.activity.mine;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import bb.lanxing.R;
import bb.lanxing.activity.base.WebActivity;
import bb.lanxing.activity.base.BasePopupActivity;
import bb.lanxing.model.database.Medal;
import bb.lanxing.util.DateUtil;
import bb.lanxing.util.image.MedalImageLoadUtil;
import java.util.LinkedHashMap;

public class MedalDetailActivity extends BasePopupActivity {
    private View dotView1;
    private View dotView2;
    private LayoutInflater layoutInflater;
    private Medal medal;
    private ViewPager viewPager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_medal_detail);
        bindView(getWindow().getDecorView());
        this.layoutInflater = LayoutInflater.from(this);
        Medal medal = (Medal) getIntent().getParcelableExtra("medal");
        this.medal = medal;
        if (medal == null) {
            finish();
            return;
        }
        this.dotView1.setEnabled(true);
        this.dotView2.setEnabled(false);
        this.viewPager.setAdapter(new MedalPagerAdapter());
        this.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrollStateChanged(int state) {
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    MedalDetailActivity.this.dotView1.setEnabled(true);
                    MedalDetailActivity.this.dotView2.setEnabled(false);
                } else if (position != 1) {
                } else {
                    MedalDetailActivity.this.dotView1.setEnabled(false);
                    MedalDetailActivity.this.dotView2.setEnabled(true);
                }
            }
        });
    }

    private void bindView(View bindSource) {
        this.viewPager = (ViewPager) bindSource.findViewById(R.id.viewPager);
        this.dotView1 = bindSource.findViewById(R.id.dotView1);
        this.dotView2 = bindSource.findViewById(R.id.dotView2);
    }

    public class MedalPagerAdapter extends PagerAdapter {
        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        MedalPagerAdapter() {
//            MedalDetailActivity.this = this$0;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View inflate;
            if (position == 0) {
                inflate = MedalDetailActivity.this.layoutInflater.inflate(R.layout.medal_detail_view, container, false);
                ImageView imageView = (ImageView) inflate.findViewById(R.id.imageView);
                TextView textView = (TextView) inflate.findViewById(R.id.stateView);
                TextView textView2 = (TextView) inflate.findViewById(R.id.showDetail);
                textView2.setVisibility(TextUtils.isEmpty(MedalDetailActivity.this.medal.getEventUrl()) ? View.GONE : View.VISIBLE);
                textView2.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(MedalDetailActivity.this, WebActivity.class);
                        intent.putExtra("web_url", MedalDetailActivity.this.medal.getEventUrl());
                        MedalDetailActivity.this.startActivity(intent);
                    }
                });
                if (MedalDetailActivity.this.medal.getIsmm() == 0) {
                    if (MedalDetailActivity.this.medal.getStartTime() > System.currentTimeMillis()) {
                        MedalDetailActivity medalDetailActivity = MedalDetailActivity.this;
                        MedalImageLoadUtil.showMedal(medalDetailActivity, medalDetailActivity.medal.getUnactivedPic(), imageView, 1);
                        textView.setText(MedalDetailActivity.this.getString(R.string.medal_status_not_start));
                    } else {
                        MedalDetailActivity medalDetailActivity2 = MedalDetailActivity.this;
                        MedalImageLoadUtil.showMedal(medalDetailActivity2, medalDetailActivity2.medal.getExpiredPic(), imageView, 1);
                        if (MedalDetailActivity.this.medal.getEndTime() >= System.currentTimeMillis()) {
                            textView.setText(MedalDetailActivity.this.getString(R.string.medal_status_not_get));
                        } else {
                            textView.setText(MedalDetailActivity.this.getString(R.string.medal_status_already_finish));
                        }
                    }
                } else if (MedalDetailActivity.this.medal.getIsmm() == 1) {
                    MedalDetailActivity medalDetailActivity3 = MedalDetailActivity.this;
                    MedalImageLoadUtil.showMedal(medalDetailActivity3, medalDetailActivity3.medal.getPic(), imageView, 1);
                    if (!TextUtils.isEmpty(MedalDetailActivity.this.medal.getMmtitle())) {
                        textView.setText(MedalDetailActivity.this.medal.getMmtitle());
                    } else {
                        textView.setText(MedalDetailActivity.this.getString(R.string.medal_status_already_get));
                    }
                }
                ((TextView) inflate.findViewById(R.id.nameView)).setText(MedalDetailActivity.this.medal.getTitle());
            } else {
                inflate = MedalDetailActivity.this.layoutInflater.inflate(R.layout.medal_detail_view_desc, container, false);
                ((TextView) inflate.findViewById(R.id.titleView)).setText(MedalDetailActivity.this.medal.getTitle());
                TextView textView3 = (TextView) inflate.findViewById(R.id.validTimeView);
                String format = DateUtil.format(MedalDetailActivity.this.medal.getStartTime(), 15);
                String format2 = DateUtil.format(MedalDetailActivity.this.medal.getEndTime(), 15);
                if (format.equals(format2)) {
                    textView3.setText(DateUtil.format(MedalDetailActivity.this.medal.getStartTime(), 15));
                } else {
                    textView3.setVisibility(DateUtil.getMilliscond("2099.12.31") > MedalDetailActivity.this.medal.getEndTime() ? View.VISIBLE : View.GONE);
                    if (textView3.getVisibility() == View.VISIBLE) {
                        StringBuffer stringBuffer = new StringBuffer();
                        stringBuffer.append(format);
                        stringBuffer.append(" - ");
                        stringBuffer.append(format2);
                        textView3.setText(stringBuffer);
                    }
                }
                LinearLayout linearLayout = (LinearLayout) inflate.findViewById(R.id.containerView);
                LinkedHashMap<String, String> detailMap = Medal.getDetailMap(MedalDetailActivity.this.medal.getDetail());
                if (detailMap != null) {
                    for (String str : detailMap.keySet()) {
                        View inflate2 = MedalDetailActivity.this.layoutInflater.inflate(R.layout.medal_desc_item, (ViewGroup) null);
                        linearLayout.addView(inflate2);
                        MedalImageLoadUtil.showMedal(MedalDetailActivity.this, str, (ImageView) inflate2.findViewById(R.id.imageView), 2);
                        ((TextView) inflate2.findViewById(R.id.textView)).setText(detailMap.get(str));
                    }
                }
            }
            container.addView(inflate);
            return inflate;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            if (object instanceof View) {
                container.removeView((View) object);
            }
        }
    }
}
